#include "include/lib.h"
#include "include/zero.h"
#include "cxx/cxx.h"
#include "memory/memory.h"
#include "boot/boot.h"
#include "corba.test.h"

using namespace zero;

namespace zero
{
extern ORB orb;
}

namespace zerotest
{
static TestResult trBase;

void corba_test_entry(laddr_t fixAddr, laddr_t picAddr)
{
	typedef ELF* (*FOO)(TestResult*); FOO func;

	memset(&trBase, sizeof(trBase), 0);

	relocateELF(fixAddr, false);
	ABIBase::push(ABIBase::create(reinterpret_cast<unsigned char*>(FIX_ELF_INITIAL_ADDRESS), os_allocator, os_free));
	func = reinterpret_cast<FOO>(ABIBase::top()->codeEntry);
	ABIBase::top()->load();
	func(&trBase)->run(&orb);

	relocateELF(picAddr, true);
	ABIBase::push(ABIBase::create(reinterpret_cast<unsigned char*>(PIC_ELF_INITIAL_ADDRESS), os_allocator, os_free));
	func = reinterpret_cast<FOO>(ABIBase::top()->codeEntry);
	ABIBase::top()->load();
	func(&trBase)->run(&orb);

	ABIBase::top()->unload();
	ABIBase::pop();
	ABIBase::top()->unload();
	ABIBase::pop();

	assert(trBase.clientCallTrace == 0x1);
	assert(trBase.serverCallTrace == 0x1);

	assert(trBase.clientInput == 0xa0b0c0d);
	assert(trBase.clientOutput == 0x1020304);
	assert(trBase.serverInput == 0x1020304);
	assert(trBase.serverOutput == 0xa0b0c0d);

	assert(trBase.serverExInput == 0xe1);
	assert(trBase.clientExCatch == 0xe1);
}
}

// vim: foldmarker=<([{,}])> foldmethod=marker
